//
//  CFRuntimeConfig.m
//  WealthElves
//
//  Created by Wealthwiz on 2017/4/26.
//  Copyright © 2017年 Wealthwiz. All rights reserved.
//

#import "CFRuntimeConfig.h"

#define CFRC_HOSTS_BETA         @"beta_hosts"
#define CFRC_HOSTS_PRODUCT      @"product_hosts"

@interface CFRuntimeConfig ()

@property (nonatomic, strong) NSDictionary *wapiServices;
@property (nonatomic, strong) NSString *activeHostsKey;
@property (nonatomic) BOOL ndFeaturesEnabled;

@end

@implementation CFRuntimeConfig

+ (CFRuntimeConfig *)sharedInstance
{
    static dispatch_once_t  onceToken;
    static CFRuntimeConfig * sSharedInstance;
    
    dispatch_once(&onceToken, ^{
        sSharedInstance = [[CFRuntimeConfig alloc] init];
    });
    return sSharedInstance;
}

- (id)init {
    self = [super init];
    if(self) {
        self.wapiServices = @{
                              CFRC_HOSTS_BETA : @{
                                      @"comment" : @"（测试版）",
                                      @"swift" : kBaseUrlStr_T,
                                      
                                      },
                              CFRC_HOSTS_PRODUCT : @{
                                      @"comment" : @"",
                                      @"swift" : kBaseUrlStr_Phone,
                                      
                                      },
                              };
#if DEBUG
        self.activeHostsKey = CFRC_HOSTS_BETA;
#else
        self.activeHostsKey = CFRC_HOSTS_PRODUCT;
#endif
        
        //        self.activeHostsKey = HVRC_HOSTS_PRODUCT;
        // read saved host type
        NSString *savedHostType = [defaults objectForKey:UDKEY_HOST_TYPE];
        if(savedHostType)
            self.activeHostsKey = savedHostType;
        
        self.ndFeaturesEnabled = NO;
    }
    return self;
}

- (NSDictionary *)activeHosts {
    return [self.wapiServices objectForKey:self.activeHostsKey];
}

- (NSString *)comment {
    return [[self activeHosts] objectForKey:@"comment"];
}

- (NSString *)swiftHost {
    return [[self activeHosts] objectForKey:@"swift"];
}


- (BOOL)betaHostsEnabled {
#if HV_ENABLE_BETA_HOSTS
    return [self.activeHostsKey isEqualToString:CFRC_HOSTS_BETA];
#else
    return NO;
#endif
}



@end
